/**
 * 
 */
package wayic.utunes.lyrics;

import org.apache.log4j.Logger;
import org.htmlparser.Parser;
import org.htmlparser.beans.StringBean;
import org.htmlparser.lexer.Lexer;
import org.htmlparser.lexer.Page;
import org.htmlparser.util.DefaultParserFeedback;
import org.htmlparser.util.ParserException;

import com.sun.org.apache.xerces.internal.util.URI;

/**
 * @author ashesh . nishant @ gmail . com
 *
 */
public class TestSiteExtractor implements Extractor {
    private static Logger  LOGGER = Logger.getLogger(TestSiteExtractor.class);
    
    public final String HOST = "mp3lyrics";
    /**
     * @see wayic.utunes.lyrics.Extractor#extract(java.lang.String)
     */
    @Override
    public String extract(String rawContent) {
        Lexer mLexer =  new Lexer (new Page (rawContent));
        Parser parser = new Parser(mLexer, new DefaultParserFeedback(DefaultParserFeedback.QUIET));
        StringBean sb = new StringBean();
        try {
            parser.visitAllNodesWith(sb);
            return sb.getStrings();
        } catch (ParserException e) {
            e.printStackTrace();
            LOGGER.debug("Extraction failed due to  - " +e.getMessage());
        }
        return null;
    }

    @Override
    public boolean canExtract(URI fromUri) {
        return fromUri.getHost().equals(HOST);
    }

}
